﻿using DayuCode.Designer;
using DayuCode.Designer.BLL;
using DayuCode.Designer.Entity;
using DayuCode.Designer.Forms;
using DayuCode.Designer.Forms.template;
using DayuCode.Designer.Model;
using DayuCode.Designer.Service;
using Sunny.UI;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace DayuCode.Designer
{
    public partial class FormMain : UIForm
    {        
        public FormMain()
        {
            InitializeComponent();

        }

        private void FormMain_Load(object sender, EventArgs e)
        {
            if (UserConfig.Instance.AppId > 0)
            {
                Project project = ProjectManager.GetProject(UserConfig.Instance.AppId);
                //chgCurrProject(project);
            }
        }

        


        private void menuProjectList_Click(object sender, EventArgs e)
        {
            FormProjects form = new FormProjects();
            form.ShowInTaskbar = false;
            form.Owner = this;
            form.ShowDialog();
            form.Dispose();
        }

        private void menuCodeTemplates_Click(object sender, EventArgs e)
        {
            FormCodeTemplates form = new FormCodeTemplates();
            form.Owner = this;
            form.Show(this);
            
        }

        private void menuFunConfig_Click(object sender, EventArgs e)
        {
            long currProjectId = 0;
            if (UserConfig.Instance.AppId != 0)
            {
                currProjectId = UserConfig.Instance.AppId;
                //Project project = ProjectManager.GetProject(UserConfig.Instance.AppId);
                //chgCurrProject(project);
                
            }
            else
            {
                FormProjectSelect form = new FormProjectSelect();
                form.Owner = this;
                form.ShowDialog(this);
                currProjectId = UserConfig.Instance.AppId;
            }
            if (currProjectId > 0)
            {
                showFunConfigForm(currProjectId);
            }
        }

        private void showFunConfigForm(long projectId)
        {
            if (projectId == 0)
            {
                this.ShowErrorTip("请先选择应用系统【应用系统->切换应用系统】");
                return;
            }
            FormFuncConfig form = new FormFuncConfig();
            form.Owner = this;
            form.SetProject(projectId);
            form.ShowDialog(this);
        }

        private void menuSelectCurrProject_Click(object sender, EventArgs e)
        {
            FormProjectSelect form = new FormProjectSelect();
            form.Owner = this;
            form.ShowDialog(this);
        }

        private void menuCodeFragment_Click(object sender, EventArgs e)
        {
            FormCodeFragments form = new FormCodeFragments();
            form.Owner = this;
            form.ShowDialog(this);
            form.Dispose();
        }
    }
}
